//
//  LJJGoodsListCollectionViewCell.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/21.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJGoodsListCollectionViewCell.h"

@interface LJJGoodsListCollectionViewCell ()

@property (strong, nonatomic) UIImageView *countryImageView;    /** 国家 **/
@property (strong, nonatomic) UIImageView *goodsItemImageView;    /** 商品图片 **/
@property (strong, nonatomic) UILabel *titleLabel;    /** 标题 **/
@property (strong, nonatomic) UILabel *priceLabel;    /** 价格 **/

@end

@implementation LJJGoodsListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.countryImageView];
        [self addSubview:self.goodsItemImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.priceLabel];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [_goodsItemImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 0, 80, 0));
    }];
    [_countryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).offset(10);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(22, 16));
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.goodsItemImageView.mas_bottom).offset(10);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.right.equalTo(weakSelf.mas_right).offset(-10);
        make.height.equalTo(@40);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(10);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.right.equalTo(weakSelf.mas_right).offset(-10);
        make.height.equalTo(@23);
    }];
}
- (void)setGoodsListModel:(LJJGoodsListModel *)goodsListModel
{
    _goodsListModel = goodsListModel;
    [_countryImageView sd_setImageWithURL:[NSURL URLWithString:goodsListModel.CountryImg]];
    [_goodsItemImageView sd_setImageWithURL:[NSURL URLWithString:goodsListModel.ImgView]];
    _titleLabel.text = goodsListModel.Title;
    _priceLabel.attributedText = [NSMutableAttributedString makeListPriceText:goodsListModel.Price oldPrice:goodsListModel.DomesticPrice];
}

#pragma mark -
#pragma mark - lazy method
- (UIImageView *)countryImageView
{
    if (!_countryImageView) {
        _countryImageView = [[UIImageView alloc] init];
    }
    return _countryImageView;
}
- (UIImageView *)goodsItemImageView
{
    if (!_goodsItemImageView) {
        _goodsItemImageView = [[UIImageView alloc] init];
    }
    return _goodsItemImageView;
}
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14.0];
        _titleLabel.numberOfLines = 2;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}
- (UILabel *)priceLabel
{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLabel;
}

@end
